home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GXEditParagraph.c
-
- Contains:
-
- Written by: Barton R. House
-
- Copyright: © 1993 by Apple Computer, Inc., All rights reserved.
-
- */
-
- #include "GXEdit.h"
- #include "GXEditDebug.h"
- #include "GXEditDoc.h"
- #include "GXEditParagraph.h"
- #include "GXEditLine.h"
- #include "GXEditNewRun.h"
- #include "GXEditStyle.h"
- #include "GXEditSelection.h"
- #include "GXEditError.h"
-
- /* GX includes */
- #include "graphics routines.h"
- #include "math routines.h"
- #include "graphics libraries.h"
- #include "layout routines.h"
-
- static void CalcOffsets(DocPtr dp, ParaPtr pp, short lineIndex);
- static void CalcStarts(DocPtr dp, ParaPtr pp, short lineIndex);
-
- static void CalcRunOffsets(DocPtr dp, ParaPtr pp, short runIndex);
-
- static void ReflowParagraphAtIndex(DocPtr dp, ParaPtr pp, short lineIndex);
- static void NewReflowParagraphAtIndex(DocPtr dp, ParaPtr pp, short lineIndex);
- static short FindWordBreak(DocPtr dp, ParaPtr pp, short startOffset, short endOffset);
-
- static void CheckAttributes(DocPtr dp, NewRunPtr rp, AttrPtr ap);
-
- static void CleanUpRuns(DocPtr dp, ParaPtr pp, short runIndex);
-
- void InsertParagraphText(DocPtr dp, ParaPtr pp, short paraOffset, void * text, short numText, short styleIndex)
- {
- LinePtr lp;
- NewRunPtr rp;
- short lineIndex;
- short lineOffset;
- short runIndex;
- short runOffset;
- long size;
-
- if(paraOffset < 0 || paraOffset > pp->numText)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* insert the text into the runs */
-
- HLock((Handle) pp->runs);
-
- /* find the run and the offset */
-
- GetNewRunIndexAndOffset(dp, pp, paraOffset, &runIndex, &runOffset);
-
- /* add the text */
-
- rp = *pp->runs + runIndex;
-
- if(rp->styleIndex != styleIndex) {
-
- if(runOffset == 0) {
-
- if(runIndex && (rp-1)->styleIndex == styleIndex) {
-
- runIndex--;
- runOffset = (rp-1)->numText;
-
- } else {
-
- pp->numRuns++;
-
- HUnlock((Handle) pp->runs);
-
- size = pp->numRuns * sizeof(NewRunRec);
- SetHandleSize((Handle) pp->runs, size);
-
- HLock((Handle) pp->runs);
-
- size = (pp->numRuns - runIndex - 1) * sizeof(NewRunRec);
- BlockMove((Ptr) (*pp->runs + runIndex), (Ptr) (*pp->runs + runIndex + 1), size);
-
- NewNewRun(dp, *pp->runs + runIndex, styleIndex);
-
- runOffset = 0;
-
- }
-
- } else if(runOffset == rp->numText) {
-
- if(runIndex < pp->numRuns - 1 && (rp+1)->styleIndex == styleIndex) {
-
- runIndex++;
- runOffset = 0;
-
- } else {
-
- runIndex++;
-
- pp->numRuns++;
-
- HUnlock((Handle) pp->runs);
-
- size = pp->numRuns * sizeof(NewRunRec);
- SetHandleSize((Handle) pp->runs, size);
-
- HLock((Handle) pp->runs);
-
- size = (pp->numRuns - runIndex - 1) * sizeof(NewRunRec);
- BlockMove((Ptr) (*pp->runs + runIndex), (Ptr) (*pp->runs + runIndex + 1), size);
-
- NewNewRun(dp, *pp->runs + runIndex, styleIndex);
-
- runOffset = 0;
-
- }
-
- } else {
-
- pp->numRuns += 2;
-
- HUnlock((Handle) pp->runs);
-
- size = pp->numRuns * sizeof(NewRunRec);
- SetHandleSize((Handle) pp->runs, size);
-
- HLock((Handle) pp->runs);
-
- size = (pp->numRuns - runIndex - 3) * sizeof(NewRunRec);
- BlockMove((Ptr) (*pp->runs + runIndex + 1), (Ptr) (*pp->runs + runIndex + 3), size);
-
- SplitNewRun(dp, *pp->runs + runIndex, runOffset, *pp->runs + runIndex + 2);
-
- NewNewRun(dp, *pp->runs + runIndex + 1, styleIndex);
-
- runIndex++;
- runOffset = 0;
-
- }
-
- rp = *pp->runs + runIndex;
-
- }
-
- InsertNewRunText(dp, rp, runOffset, text, numText);
-
- HUnlock((Handle) pp->runs);
-
- /* insert the text into the lines */
-
- HLock((Handle) pp->lines);
-
- /* find the gxLine and the offset */
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, false);
-
- lp = *pp->lines + lineIndex;
-
- InsertDocLineText(dp, lp, lineOffset, numText);
-
- /* update the text count */
-
- pp->numText += numText;
-
- HUnlock((Handle) pp->lines);
-
- CalcRunOffsets(dp, pp, runIndex);
- CalcOffsets(dp, pp, lineIndex);
-
- pp->dirty = true; /* CalcStarts(dp, pp, lineIndex); */
-
- if(lineIndex > 0) lineIndex--;
-
- (*pp->lines)[lineIndex].reflow = true;
-
- pp->reflow = true;
-
- }
-
- void DrawParagraph(DocPtr dp, ParaPtr pp, long start, long end)
- {
- LinePtr lp;
- short lineIndex;
-
- if(pp->dirty) /* we are using gxLine starts, check if paragraph is dirty */
- CalcStarts(dp, pp, 0);
-
- HLock((Handle) pp->lines);
-
- for(lineIndex = 0, lp = *pp->lines; lineIndex < pp->numLines; lineIndex++, lp++)
- if((pp->start + lp->start) < end && (pp->start + lp->start + GetLineHeight(dp, pp ,lp)) > start)
- DrawDocLine(dp, pp, lp);
-
- HUnlock((Handle) pp->lines);
-
- pp->drawn = true;
-
- }
-
- void ReflowParagraph(DocPtr dp, ParaPtr pp)
- {
- LinePtr lp;
- short lineIndex;
-
- lp = *pp->lines;
-
- for(lineIndex=0; lineIndex < pp->numLines; lineIndex++, lp++)
- if(lp->reflow) {
- ReflowParagraphAtIndex(dp, pp, lineIndex);
- break;
- }
-
- pp->reflow = false;
- }
-
- void gxEditNewParagraph(DocPtr dp, ParaPtr pp, short styleIndex)
- {
- char c;
-
- pp->numRuns = 1;
- pp->runs = (NewRunHan) NewHandle(sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- NewNewRun(dp, *pp->runs, styleIndex);
-
- pp->numLines = 1;
- pp->lines = (LineHan) NewHandle(sizeof(LineRec));
-
- pp->layoutOptions = dp->currentLayoutOptions;
-
- HLock((Handle) pp->lines);
-
- NewDocLine(*pp->lines);
-
- /* add newline character */
- c = '\r';
-
- InsertNewRunText(dp, *pp->runs, 0, &c, 1);
-
- InsertDocLineText(dp, *pp->lines, 0, 1);
-
- HUnlock((Handle) pp->runs);
-
- pp->start = 0;
- pp->width = dp->lineWidth;
- pp->docOffset = 0;
- pp->numText = 1;
- pp->drawn = false;
- pp->reflow = true;
- pp->height = GetLineHeight(dp, pp, *pp->lines);
-
- HUnlock((Handle) pp->lines);
-
-
- }
-
- void HitTestParagraph(DocPtr dp, ParaPtr pp, Point where, short * paraOffsetPtr, Boolean * endOfLinePtr)
- {
- LinePtr lp;
- short lineIndex;
- short lineOffset;
- short paraOffset;
- Boolean endOfLine;
-
- if(pp->dirty) /* we are using gxLine starts, check if paragraph is dirty */
- CalcStarts(dp, pp, 0);
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
-
- paraOffset = 0; /* in case of error */
- endOfLine = false;
-
- if(dp->verticalText) {
- for(lineIndex=0; lineIndex < pp->numLines; lineIndex++, lp++)
- if(where.h >= lp->start && where.h < (lp->start + GetLineHeight(dp, pp, lp))) {
-
- where.h -= lp->start;
-
- lineOffset = HitTestDocLine(dp, pp, lp, where);
-
- if(lineOffset == lp->numText)
- endOfLine = true;
-
- paraOffset = lineOffset + lp->paraOffset;
- break;
- }
- } else {
- for(lineIndex=0; lineIndex < pp->numLines; lineIndex++, lp++)
- if(where.v >= lp->start && where.v < (lp->start + GetLineHeight(dp, pp, lp))) {
-
- where.v -= lp->start;
-
- lineOffset = HitTestDocLine(dp, pp, lp, where);
-
- if(lineOffset == lp->numText)
- endOfLine = true;
-
- paraOffset = lineOffset + lp->paraOffset;
- break;
- }
- }
-
- if(lineIndex == pp->numLines)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HUnlock((Handle) pp->lines);
-
- *paraOffsetPtr = paraOffset;
- *endOfLinePtr = endOfLine;
-
- }
-
- void ParagraphPosition(DocPtr dp, ParaPtr pp, short paraOffset, long * start, long * end)
- {
- LinePtr lp;
- short lineIndex;
- short lineOffset;
-
- if(pp->dirty) /* we are using gxLine starts, check if paragraph is dirty */
- CalcStarts(dp, pp, 0);
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, false);
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + lineIndex;
-
- DocLinePosition(lp, start, end);
-
- *start += lp->start;
- *end += lp->start;
-
- HUnlock((Handle) pp->lines);
-
- }
-
- short GetParagraphOffset(DocPtr dp, ParaPtr pp, short offsetType, short paraOffset)
- {
- LinePtr lp;
- short lineOffset, lineIndex;
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, false);
-
- lp = *pp->lines + lineIndex;
-
- if(offsetType == kVisualLeftOffset && lineOffset == 0) {
-
- if(lineIndex == 0)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- lineIndex--;
- lp--;
- lineOffset = lp->numText;
- }
-
- paraOffset = lp->paraOffset;
-
- return(paraOffset + GetLineOffset(dp, pp, lp, offsetType, lineOffset));
-
- }
-
- void ParagraphClear(DocPtr dp, ParaPtr pp, short paraOffset, short numText)
- {
- LinePtr lp;
- NewRunPtr rp;
- short runIndex;
- short runOffset;
- short lineIndex;
- short lineOffset;
- long size;
- short index;
- short lineText;
- short runNumText;
- short runText;
-
- if(numText == 0)
- return;
-
- if(paraOffset < 0 || paraOffset >= pp->numText)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(paraOffset + numText > pp->numText)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* clear the runs */
-
- HLock((Handle) pp->runs);
-
- GetNewRunIndexAndOffset(dp, pp, paraOffset, &runIndex, &runOffset);
-
- runNumText = numText;
-
- index = runIndex;
-
- if(runOffset != 0) {
-
- rp = *pp->runs + index;
-
- runText = rp->numText - runOffset;
-
- if(runText > numText)
- runText = numText;
-
- NewRunClear(dp, rp, runOffset, runText);
-
- runNumText -= runText;
-
- index++;
- }
-
- while(runNumText) {
-
- if(index >= pp->numRuns)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- rp = *pp->runs + index;
-
- if(runNumText >= rp->numText) {
-
- runNumText -= rp->numText;
-
- /* dispose the run */
-
- DisposeNewRun(dp, rp);
-
- pp->numRuns--;
-
- size = (pp->numRuns - index) * sizeof(NewRunRec);
- BlockMove((Ptr) (rp+1), (Ptr) rp, size);
-
- HUnlock((Handle) pp->runs);
-
- size = pp->numRuns * sizeof(NewRunRec);
- SetHandleSize((Handle) pp->runs, size);
-
- HLock((Handle) pp->runs);
-
- } else {
-
- NewRunClear(dp, rp, 0, runNumText);
-
- runNumText = 0;
- }
-
- }
-
- HUnlock((Handle) pp->runs);
-
- /* clear the lines */
-
- HLock((Handle) pp->lines);
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, false);
-
- index = lineIndex;
-
- if(lineOffset != 0) {
-
- lp = *pp->lines + index;
-
- lineText = lp->numText - lineOffset;
-
- if(lineText > numText)
- lineText = numText;
-
- DocLineClear(dp, lp, lineOffset, lineText);
-
- numText -= lineText;
-
- index++;
-
- }
-
- while(numText > 0) {
-
- lp = *pp->lines + index;
-
- if(numText >= lp->numText) {
-
- numText -= lp->numText;
-
- /* dispose gxLine */
-
- DisposeDocLine(lp);
-
- pp->numLines--;
-
- size = (pp->numLines - index) * sizeof(LineRec);
- BlockMove((Ptr) (lp+1), (Ptr) lp, size);
-
- HUnlock((Handle) pp->lines);
-
- size = pp->numLines * sizeof(LineRec);
- SetHandleSize((Handle) pp->lines, size);
-
- HLock((Handle) pp->lines);
-
- } else {
-
- DocLineClear(dp, lp, 0, numText);
-
- numText = 0;
-
- }
-
- }
-
- HUnlock((Handle) pp->lines);
-
- CalcRunOffsets(dp, pp, runIndex);
- CleanUpRuns(dp, pp, runIndex);
- CalcOffsets(dp, pp, lineIndex);
-
- pp->dirty = true;
-
- if(lineIndex != 0) lineIndex--; /* might be able to reflow differently now */
-
- (*pp->lines)[lineIndex].reflow = true;
-
- pp->reflow = true;
- }
-
- void JoinParagraphs(DocPtr dp, ParaPtr top, ParaPtr bottom)
- {
- short lineIndex;
- long size;
- LinePtr lp;
- NewRunPtr last, first;
- short runIndex;
-
- /* remove newline from last gxLine of top paragraph */
-
- /* remove it from the run */
-
- last = *top->runs + top->numRuns - 1;
- NewRunClear(dp, last, last->numText - 1, 1);
-
- /* remove it from the gxLine */
-
- lp = *top->lines + top->numLines - 1;
- DocLineClear(dp, lp, lp->numText - 1, 1);
-
- /* save the gxLine index from which we will calc starts and offsets */
-
- lineIndex = top->numLines - 1;
-
- /* join the runs */
-
- HLock((Handle) top->runs);
- HLock((Handle) bottom->runs);
-
- runIndex = top->numRuns - 1;
-
- last = *top->runs + runIndex;
- first = *bottom->runs;
-
- if(last->styleIndex == first->styleIndex) {
-
- JoinNewRuns(dp, last, first);
-
- HUnlock((Handle) top->runs);
-
- size = (top->numRuns + bottom->numRuns - 1) * sizeof(NewRunRec);
- SetHandleSize((Handle) top->runs, size);
-
- HLock((Handle) top->runs);
-
- size = (bottom->numRuns - 1) * sizeof(NewRunRec);
- BlockMove((Ptr) (*bottom->runs + 1), (Ptr) (*top->runs + top->numRuns), size);
-
- top->numRuns += bottom->numRuns - 1;
-
- } else {
-
- HUnlock((Handle) top->runs);
-
- size = (top->numRuns + bottom->numRuns) * sizeof(NewRunRec);
- SetHandleSize((Handle) top->runs, size);
-
- HLock((Handle) top->runs);
-
- size = bottom->numRuns * sizeof(NewRunRec);
- BlockMove((Ptr) (*bottom->runs), (Ptr) (*top->runs + top->numRuns), size);
-
- top->numRuns += bottom->numRuns;
-
- }
-
- HUnlock((Handle) top->runs);
- HUnlock((Handle) bottom->runs);
-
- /* join the lines */
-
- size = (top->numLines + bottom->numLines) * sizeof(LineRec);
- SetHandleSize((Handle) top->lines, size);
-
- size = bottom->numLines * sizeof(LineRec);
- BlockMove((Ptr) *bottom->lines, (Ptr) (*top->lines + top->numLines), size);
-
- top->numLines += bottom->numLines;
-
- CalcRunOffsets(dp, top, runIndex);
- CleanUpRuns(dp, top, runIndex);
- CalcOffsets(dp, top, lineIndex);
-
- top->dirty = true; /* CalcStarts(dp, top, lineIndex); */
-
- (*top->lines)[lineIndex].reflow = true;
-
- top->reflow = true;
-
- }
-
- void gxEditDisposeParagraph(DocPtr dp, ParaPtr pp)
- {
- LinePtr lp;
- NewRunPtr rp;
- short lineIndex;
- short runIndex;
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
-
- for(lineIndex=0; lineIndex<pp->numLines; lineIndex++, lp++)
- DisposeDocLine(lp);
-
- HUnlock((Handle) pp->lines);
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs;
-
- for(runIndex=0; runIndex<pp->numRuns; runIndex++, rp++)
- DisposeNewRun(dp, rp);
-
- HUnlock((Handle) pp->runs);
-
- DisposeHandle((Handle) pp->lines);
- DisposeHandle((Handle) pp->runs);
-
- }
-
- void SplitParagraph(DocPtr dp, ParaPtr pp, short paraOffset, ParaPtr newPara)
- {
- LinePtr lp;
- short lineIndex;
- short lineOffset;
- short runIndex;
- short runOffset;
- long size;
- char c;
- short styleIndex;
-
- if(paraOffset < 0 || paraOffset > pp->numText)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- GetNewRunIndexAndOffset(dp, pp, paraOffset, &runIndex, &runOffset);
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, false);
-
- newPara->numRuns = pp->numRuns - runIndex;
- newPara->numLines = pp->numLines - lineIndex;
- newPara->numText = pp->numText - paraOffset;
- newPara->width = pp->width;
- newPara->layoutOptions = pp->layoutOptions;
-
- /* split runs */
-
- size = sizeof(NewRunRec) * newPara->numRuns;
- newPara->runs = (NewRunHan) NewHandle(size);
- BlockMove((Ptr) (*pp->runs + runIndex), (Ptr) *newPara->runs, size);
-
- if(runOffset || !runIndex) {
-
- HLock((Handle) newPara->runs);
- HLock((Handle) pp->runs);
-
- SplitNewRun(dp, *pp->runs + runIndex, runOffset, *newPara->runs);
- pp->numRuns = runIndex + 1;
-
- HUnlock((Handle) pp->runs);
- HUnlock((Handle) newPara->runs);
-
- } else
- pp->numRuns = runIndex;
-
-
- /* split lines */
-
- size = sizeof(LineRec) * newPara->numLines;
- newPara->lines = (LineHan) NewHandle(size);
- BlockMove((Ptr) (*pp->lines + lineIndex), (Ptr) *newPara->lines, size);
-
- HLock((Handle) newPara->lines);
- HLock((Handle) pp->lines);
-
- SplitDocLine(dp, *pp->lines + lineIndex, lineOffset, *newPara->lines);
- pp->numLines = lineIndex + 1;
-
- HUnlock((Handle) pp->lines);
- HUnlock((Handle) newPara->lines);
-
- CalcRunOffsets(dp, newPara, 0);
- CleanUpRuns(dp, newPara, 0); /* this may not be needed */
- CalcOffsets(dp, newPara, 0);
-
- newPara->dirty = true;
-
- (*newPara->lines)[0].reflow = true;
-
- newPara->reflow = true;
-
- /* adjust the original paragraph */
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + (pp->numLines - 1);
-
- pp->numText = paraOffset;
-
- pp->dirty = true;
-
- HUnlock((Handle) pp->lines);
-
- SetHandleSize((Handle) pp->lines, pp->numLines * sizeof(LineRec));
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- /* add newline character at the end of the last line of original paragraph using the style at that point*/
-
- c = '\r';
- styleIndex = (*pp->runs)[pp->numRuns-1].styleIndex;
-
- InsertParagraphText(dp, pp, pp->numText, &c, 1, styleIndex);
-
- CleanUpRuns(dp, pp, 0); /* this is needed only to take of the possibility of empty runs */
- /* this should be cleaned up as empty runs only happen during one specific case
- 1) zero length runs are currently not supported
- 2) this causes zero length runs to be created when a paragraph is spit at the star
- *) see above check if(runOffset || !runIndex) */
-
- }
-
- void GetParagraphAttributes(DocPtr dp, ParaPtr pp, AttrPtr ap, short startParaOffset, short endParaOffset)
- {
- NewRunPtr rp;
- short startRunIndex;
- short startRunOffset;
- short endRunIndex;
- short endRunOffset;
- short runIndex;
-
- /* get the attributes from the runs */
-
- HLock((Handle) pp->runs);
-
- GetNewRunIndexAndOffset(dp, pp, startParaOffset, &startRunIndex, &startRunOffset);
- GetNewRunIndexAndOffset(dp, pp, endParaOffset, &endRunIndex, &endRunOffset);
-
- /* fix up end of selection if it is at the start of a run */
-
- if(endRunOffset == 0 && endRunIndex) {
-
- endRunIndex--;
- endRunOffset = (*pp->runs)[endRunIndex].numText;
-
- /* can this be removed now ??? */
-
- if(startRunIndex > endRunIndex) {
- startRunIndex = endRunIndex;
- startRunOffset = endRunOffset;
- }
-
- }
-
- runIndex = startRunIndex;
- rp = *pp->runs + runIndex;
-
- while(runIndex <= endRunIndex) {
-
- CheckAttributes(dp, rp, ap);
-
- runIndex++;
- rp++;
-
- }
-
- HUnlock((Handle) pp->runs);
-
- }
-
- #ifdef NO_LONGER_NEEDED
- Boolean SetParagraphTextFonts(DocPtr dp, ParaPtr pp, short numFonts, gxFont * srcFonts, gxFont * dstFonts,
- short startParaOffset, short endParaOffset)
- {
- short startLineIndex;
- short startLineOffset;
- short endLineIndex;
- short endLineOffset;
- LinePtr lp;
- NewRunPtr rp;
- short startOffset;
- short endOffset;
- Boolean modified;
- short startRunIndex;
- short startRunOffset;
- short endRunIndex;
- short endRunOffset;
- short runIndex;
- long size;
- short fontIndex;
- gxFont runTextFont;
-
- /* set the gxFont of the runs */
-
- GetNewRunIndexAndOffset(dp, pp, startParaOffset, &startRunIndex, &startRunOffset);
- GetNewRunIndexAndOffset(dp, pp, endParaOffset, &endRunIndex, &endRunOffset);
-
- /* fix up end of selection if it is at the start of a run */
-
- if(endRunOffset == 0 && endRunIndex) {
-
- endRunIndex--;
- endRunOffset = (*pp->runs)[endRunIndex].numText;
-
- /* when we special case the empty selection -- this can be removed */
-
- if(startRunIndex > endRunIndex) {
- startRunIndex = endRunIndex;
- startRunOffset = endRunOffset;
- }
-
- }
-
- runIndex = startRunIndex;
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- modified = false;
-
- while(runIndex <= endRunIndex) {
-
- runTextFont = GetDocStyleTextFont(dp, rp->styleIndex);
-
- for(fontIndex=0; fontIndex<numFonts; fontIndex++)
- if(srcFonts[fontIndex] == runTextFont)
- break;
-
- if(fontIndex != numFonts && runTextFont != dstFonts[fontIndex]) {
-
- if(runIndex == startRunIndex)
- startOffset = startRunOffset;
- else
- startOffset = 0;
-
- if(runIndex == endRunIndex)
- endOffset = endRunOffset;
- else
- endOffset = rp->numText;
-
- if(startOffset != 0) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, startOffset, rp+1);
-
- runIndex++;
- rp++;
- endOffset -= startOffset;
- startOffset = 0;
-
- }
-
- if(endOffset != rp->numText) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, endOffset, rp+1);
-
- runIndex++;
-
- }
-
- if(startOffset == 0 && endOffset == rp->numText)
- SetNewRunTextFont(dp, rp, dstFonts[fontIndex]);
- else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* make any lines that contain this run as dirty and need to be reflowed */
-
- GetLineIndexAndOffset(dp, pp, rp->paraOffset, &startLineIndex, &startLineOffset, false);
- GetLineIndexAndOffset(dp, pp, rp->paraOffset + rp->numText, &endLineIndex, &endLineOffset, false);
-
- for(lp = *pp->lines + startLineIndex;startLineIndex <= endLineIndex; startLineIndex++, lp++) {
- lp->dirty = true;
- lp->reflow = true;
- }
-
- modified = true;
-
- }
-
- runIndex++;
- rp++;
-
- }
-
- HUnlock((Handle) pp->runs);
-
- /* do calculation starting from startRunIndex -- this is not optimal */
-
- if(modified) {
-
- CalcRunOffsets(dp, pp, startRunIndex);
- CleanUpRuns(dp, pp, startRunIndex);
-
- GetLineIndexAndOffset(dp, pp, startParaOffset, &startLineIndex, &startLineOffset, false);
- CalcOffsets(dp, pp, startLineIndex);
-
- pp->dirty = true; /* CalcStarts(dp, pp, startLineIndex); */
-
- pp->reflow = true;
- }
-
- return(modified);
-
- }
-
- Boolean SetParagraphTextSize(DocPtr dp, ParaPtr pp, short textSize,
- short startParaOffset, short endParaOffset)
- {
- short startLineIndex;
- short startLineOffset;
- short endLineIndex;
- short endLineOffset;
- LinePtr lp;
- short startOffset;
- short endOffset;
- Boolean modified;
- NewRunPtr rp;
- short startRunIndex;
- short startRunOffset;
- short endRunIndex;
- short endRunOffset;
- short runIndex;
- long size;
- short runTextSize;
-
- /* set text size of runs */
-
- GetNewRunIndexAndOffset(dp, pp, startParaOffset, &startRunIndex, &startRunOffset);
- GetNewRunIndexAndOffset(dp, pp, endParaOffset, &endRunIndex, &endRunOffset);
-
- /* fix up end of selection if it is at the start of a run */
-
- if(endRunOffset == 0 && endRunIndex) {
-
- endRunIndex--;
- endRunOffset = (*pp->runs)[endRunIndex].numText;
-
- /* when we special case the empty selection -- this can be removed */
-
- if(startRunIndex > endRunIndex) {
- startRunIndex = endRunIndex;
- startRunOffset = endRunOffset;
- }
-
- }
-
- runIndex = startRunIndex;
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- modified = false;
-
- while(runIndex <= endRunIndex) {
-
- runTextSize = GetDocStyleTextSize(dp, rp->styleIndex);
-
- if(runTextSize != textSize) {
-
- if(runIndex == startRunIndex)
- startOffset = startRunOffset;
- else
- startOffset = 0;
-
- if(runIndex == endRunIndex)
- endOffset = endRunOffset;
- else
- endOffset = rp->numText;
-
- if(startOffset != 0) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, startOffset, rp+1);
-
- runIndex++;
- rp++;
- endOffset -= startOffset;
- startOffset = 0;
-
- }
-
- if(endOffset != rp->numText) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, endOffset, rp+1);
-
- runIndex++;
-
- }
-
- if(startOffset == 0 && endOffset == rp->numText)
- SetNewRunTextSize(dp, rp, textSize);
- else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* make any lines that contain this run as dirty and need to be reflowed */
-
- GetLineIndexAndOffset(dp, pp, rp->paraOffset, &startLineIndex, &startLineOffset, false);
- GetLineIndexAndOffset(dp, pp, rp->paraOffset + rp->numText, &endLineIndex, &endLineOffset, false);
-
- for(lp = *pp->lines + startLineIndex;startLineIndex <= endLineIndex; startLineIndex++, lp++) {
- lp->dirty = true;
- lp->reflow = true;
- }
-
- modified = true;
-
- }
-
- runIndex++;
- rp++;
-
- }
-
- HUnlock((Handle) pp->runs);
-
- /* do calculation starting from runLineIndex -- this is not optimal */
-
- if(modified) {
-
- CalcRunOffsets(dp, pp, startRunIndex);
- CleanUpRuns(dp, pp, startRunIndex);
-
- GetLineIndexAndOffset(dp, pp, startParaOffset, &startLineIndex, &startLineOffset, false);
- CalcOffsets(dp, pp, startLineIndex);
-
- pp->dirty = true; /* CalcStarts(dp, pp, startLineIndex); */
-
- pp->reflow = true;
- }
-
- return(modified);
-
- }
- #endif
-
- Boolean SetParagraphStyles(DocPtr dp, ParaPtr pp, short numStyles, short *oldStyles, short *newStyles,
- short startParaOffset, short endParaOffset)
- {
- short startLineIndex;
- short startLineOffset;
- short endLineIndex;
- short endLineOffset;
- LinePtr lp;
- short startOffset;
- short endOffset;
- Boolean modified;
- NewRunPtr rp;
- short startRunIndex;
- short startRunOffset;
- short endRunIndex;
- short endRunOffset;
- short runIndex;
- long size;
- short * stylePtr;
- short i;
-
- /* set run styles */
-
- GetNewRunIndexAndOffset(dp, pp, startParaOffset, &startRunIndex, &startRunOffset);
- GetNewRunIndexAndOffset(dp, pp, endParaOffset, &endRunIndex, &endRunOffset);
-
- /* fix up end of selection if it is at the start of a run */
-
- if(endRunOffset == 0 && endRunIndex) {
-
- endRunIndex--;
- endRunOffset = (*pp->runs)[endRunIndex].numText;
-
- /* when we special case the empty selection -- this can be removed */
-
- if(startRunIndex > endRunIndex) {
- startRunIndex = endRunIndex;
- startRunOffset = endRunOffset;
- }
-
- }
-
- runIndex = startRunIndex;
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- modified = false;
-
- while(runIndex <= endRunIndex) {
-
- stylePtr = oldStyles;
-
- for(i=0; i<numStyles; i++, stylePtr++)
- if(*stylePtr == rp->styleIndex)
- break;
-
- if(i == numStyles)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(rp->styleIndex != newStyles[i]) {
-
- if(runIndex == startRunIndex)
- startOffset = startRunOffset;
- else
- startOffset = 0;
-
- if(runIndex == endRunIndex)
- endOffset = endRunOffset;
- else
- endOffset = rp->numText;
-
- if(startOffset != 0) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, startOffset, rp+1);
-
- runIndex++;
- rp++;
- endOffset -= startOffset;
- startOffset = 0;
-
- }
-
- if(endOffset != rp->numText) {
-
- pp->numRuns++;
- endRunIndex++;
-
- HUnlock((Handle) pp->runs);
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- size = sizeof(NewRunRec) * (pp->numRuns - runIndex - 2);
- BlockMove((Ptr) (rp+1), (Ptr) (rp+2), size);
-
- SplitNewRun(dp, rp, endOffset, rp+1);
-
- runIndex++;
- }
-
- if(startOffset == 0 && endOffset == rp->numText) {
-
- /* BUG ALERT -- This assumes that the caller will never use this call
- to change the gxFont or size */
-
- DecrementDocStyleRefCount(dp, rp->styleIndex);
-
- rp->styleIndex = newStyles[i];
-
- IncrementDocStyleRefCount(dp, rp->styleIndex);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* make any lines that contain this run as dirty and need to be reflowed */
-
- GetLineIndexAndOffset(dp, pp, rp->paraOffset, &startLineIndex, &startLineOffset, false);
- GetLineIndexAndOffset(dp, pp, rp->paraOffset + rp->numText, &endLineIndex, &endLineOffset, false);
-
- for(lp = *pp->lines + startLineIndex;startLineIndex <= endLineIndex; startLineIndex++, lp++) {
- lp->dirty = true;
- lp->reflow = true;
- }
-
- modified = true;
-
-
- }
-
- runIndex++;
- rp++;
-
- }
-
- HUnlock((Handle) pp->runs);
-
- /* do calculation starting from runLineIndex -- this is not optimal */
-
- if(modified) {
-
- CalcRunOffsets(dp, pp, startRunIndex);
- CleanUpRuns(dp, pp, startRunIndex);
-
- GetLineIndexAndOffset(dp, pp, startParaOffset, &startLineIndex, &startLineOffset, false);
- CalcOffsets(dp, pp, startLineIndex);
-
- pp->dirty = true; /* CalcStarts(dp, pp, startLineIndex); */
-
- pp->reflow = true;
- }
-
- return(modified);
-
- }
-
- short GetParagraphHeight(DocPtr dp, ParaPtr pp)
- {
- if(pp->dirty)
- CalcStarts(dp, pp, 0);
-
- return(pp->height);
- }
-
- static void ReflowParagraphAtIndex(DocPtr dp, ParaPtr pp, short lineIndex)
- {
- LinePtr lp;
- short i;
- long textRunCount;
- short * textRunLengths;
- void ** textPtrs;
- long styleRunCount;
- short * styleRunLengths;
- gxStyle * styles;
- short breakPoint;
- short lastBreakPoint;
- short ** breakPoints;
- short * bp;
- short numBreakPoints;
- short numLayoutText;
- gxShape layout;
- short startLineIndex;
- short numLines;
- short numText;
- long size;
- short paraOffset;
- short startRunIndex;
- short startRunOffset;
- short runOffset;
- NewRunPtr rp;
-
- if(lineIndex < 0 || lineIndex >= pp->numLines)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- startLineIndex = lineIndex;
- numLines = pp->numLines - lineIndex;
-
- /* build a layout of all the runs starting with the gxLine lineIndex */
-
- GetNewRunIndexAndOffset(dp, pp, (*pp->lines)[lineIndex].paraOffset, &startRunIndex, &startRunOffset);
-
- textRunCount = pp->numRuns - startRunIndex;
-
- HLock((Handle) pp->lines);
-
- /* setup the run info to be passed to GXNewLayout */
-
- textRunLengths = (short *) NewPtr(textRunCount * sizeof(short));
- textPtrs = (void **) NewPtr(textRunCount * sizeof(void *));
- styles = (gxStyle *) NewPtr(textRunCount * sizeof(gxStyle));
-
- runOffset = startRunOffset;
- rp = *pp->runs + startRunIndex;
-
- for(i=0; i < textRunCount; i++, rp++) {
-
- textRunLengths[i] = (rp->numText - runOffset);
- styles[i] = GetDocStyle(dp, rp->styleIndex)->textStyle;
-
- HLock((Handle) rp->text);
-
- textPtrs[i] = (Ptr) *rp->text + (runOffset);
-
- runOffset = 0;
- }
-
- styleRunCount = textRunCount;
- styleRunLengths = textRunLengths;
-
- /* allocate the new layout */
-
- layout = GXNewLayout(textRunCount, textRunLengths, (void *) textPtrs,
- styleRunCount, styleRunLengths, styles, 0, nil, nil,
- nil, nil);
-
- /* now we can work with the layout to find the break points */
-
- numLayoutText = pp->numText - (*pp->lines)[lineIndex].paraOffset;
- lastBreakPoint = 0;
-
- breakPoints = (short **) NewHandle(0);
- numBreakPoints = 0;
-
- paraOffset = (*pp->lines)[startLineIndex].paraOffset;
-
- do {
-
- breakPoint = GXGetLayoutBreakOffset(layout, lastBreakPoint, ff(pp->width),
- 0, nil, nil, nil, nil);
-
- if(breakPoint == (numLayoutText - 1)) /* don't break at end of paragraph */
- breakPoint++;
-
- if(breakPoint != numLayoutText) {
-
- breakPoint = FindWordBreak(dp, pp, lastBreakPoint + paraOffset, breakPoint + paraOffset);
- breakPoint -= paraOffset;
-
- }
-
- PtrAndHand((Ptr) &breakPoint, (Handle) breakPoints, sizeof(short));
- numBreakPoints++;
-
- lastBreakPoint = breakPoint;
-
- } while(breakPoint != numLayoutText);
-
- /* unlock the run text */
-
- rp = *pp->runs + startRunIndex;
- for(i=0; i < textRunCount; i++, rp++)
- HUnlock((Handle) rp->text);
-
-
- /* free up temporary data structures */
-
- DisposePtr((Ptr) textRunLengths);
- DisposePtr((Ptr) textPtrs);
- DisposePtr((Ptr) styles);
-
- GXDisposeShape(layout);
-
- /* now fix up the actual lines */
-
- lp = *pp->lines + lineIndex;
-
- HLock((Handle) breakPoints);
-
- bp = *breakPoints;
- numText = *bp;
-
- for(i=0; i < numBreakPoints; i++, bp++) {
-
- while(lp->numText != numText) {
-
- if(lp->numText < numText) {
-
- if(lineIndex == pp->numLines-1)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- JoinDocLines(lp, lp+1);
-
- size = (pp->numLines - lineIndex - 2) * sizeof(LineRec);
-
- BlockMove((Ptr) (lp+2), (Ptr) (lp+1), size);
-
- pp->numLines--;
-
- HUnlock((Handle) pp->lines);
-
- SetHandleSize((Handle) pp->lines, pp->numLines * sizeof(LineRec));
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + lineIndex;
-
- } else {
-
- HUnlock((Handle) pp->lines);
-
- pp->numLines++;
-
- SetHandleSize((Handle) pp->lines, pp->numLines * sizeof(LineRec));
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + lineIndex;
-
- size = (pp->numLines - 2 - lineIndex) * sizeof(LineRec);
-
- BlockMove((Ptr) (lp+1), (Ptr) (lp+2), size);
-
- SplitDocLine(dp, lp, numText, lp+1);
-
- }
-
- }
-
- lp++;
- lineIndex++;
-
- numText = *(bp+1) - *bp;
-
- }
-
- HUnlock((Handle) breakPoints);
-
- DisposeHandle((Handle) breakPoints);
-
- HUnlock((Handle) pp->lines);
-
- /* calculate starts and offsets -- set height */
-
- CalcOffsets(dp, pp, startLineIndex);
-
- pp->dirty = true; /* CalcStarts(dp, pp, startLineIndex); */
-
- }
-
- static void CalcRunOffsets(DocPtr dp, ParaPtr pp, short runIndex)
- {
- short paraOffset;
- NewRunPtr rp;
-
- /* do the runs */
-
- if(runIndex < 0 || runIndex >= pp->numRuns)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(pp->numRuns == 0)
- return;
-
- rp = *pp->runs + runIndex;
-
- if(runIndex == 0) {
-
- rp->paraOffset = 0;
-
- } else {
-
- runIndex--;
- rp--;
-
- }
-
- paraOffset = rp->paraOffset + rp->numText;
-
- runIndex++;
- rp++;
-
- for(; runIndex < pp->numRuns; runIndex++, rp++) {
-
- rp->paraOffset = paraOffset;
-
- paraOffset += rp->numText;
-
- }
-
- }
-
- static void CalcOffsets(DocPtr dp, ParaPtr pp, short lineIndex)
- {
- LinePtr lp;
- short paraOffset;
-
- if(lineIndex < 0 || lineIndex >= pp->numLines)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + lineIndex;
-
- if(lineIndex == 0) {
-
- lp->paraOffset = 0;
-
- } else {
-
- lp--;
- lineIndex--;
-
- }
-
- paraOffset = lp->paraOffset + lp->numText;
-
- lineIndex++;
- lp++;
-
- for(; lineIndex < pp->numLines; lineIndex++, lp++) {
-
- lp->paraOffset = paraOffset;
- paraOffset += lp->numText;
-
- }
-
- pp->numText = paraOffset;
-
- HUnlock((Handle) pp->lines);
-
- }
-
- static void CalcStarts(DocPtr dp, ParaPtr pp, short lineIndex)
- {
- LinePtr lp;
- short start;
-
- if(lineIndex < 0 || lineIndex >= pp->numLines)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines + lineIndex;
-
- if(lineIndex == 0) {
-
- lp->start = 0;
-
- } else {
-
- lp--;
- lineIndex--;
-
- }
-
- start = lp->start + GetLineHeight(dp, pp, lp);
-
- lineIndex++;
- lp++;
-
- for(; lineIndex < pp->numLines; lineIndex++, lp++) {
-
- if(lp->start != start)
- lp->drawn = false; /* the gxLine has moved -- redraw */
-
- lp->start = start;
-
- start += GetLineHeight(dp, pp, lp);
-
- }
-
- pp->height = start;
-
- HUnlock((Handle) pp->lines);
-
- pp->dirty = false;
- }
-
- static short FindWordBreak(DocPtr dp, ParaPtr pp, short startOffset, short endOffset)
- {
- NewRunPtr rp;
- short remain;
- short runIndex;
- short runOffset;
- short textToCheck;
- char * ptr;
- StylePtr style;
-
- textToCheck = endOffset - startOffset;
-
- rp = *pp->runs;
-
- for(runIndex = 0; runIndex < pp->numRuns; runIndex++, rp++)
- if((rp->paraOffset + rp->numText) >= endOffset)
- break;
-
- if(runIndex == pp->numRuns)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- remain = rp->paraOffset + rp->numText - endOffset - 1;
- ptr = (char *) *rp->text + endOffset - rp->paraOffset;
-
- /* scan forward for the first non-space */
- while (runIndex < pp->numRuns)
- {
- style = GetDocStyle(dp, rp->styleIndex);
-
- if (style->platform != gxGlyphPlatform)
- {
- while (remain > 0)
- {
- endOffset += 1;
- if (*ptr == ' ')
- {
- remain -= 1;
- ptr += 1;
- }
- else
- break;
- }
-
- if (remain > 0)
- break;
- }
-
- runIndex += 1;
- rp += 1;
- remain = rp->numText;
- ptr = (char *) *rp->text;
- }
-
- if (runIndex == pp->numRuns)
- return endOffset;
-
- runOffset = endOffset - rp->paraOffset;
-
- /* now scan backwards for the first space */
-
- for(; runIndex >= 0; runIndex--, rp--) {
-
- /* skip over runs of glyph indicies */
-
- style = GetDocStyle(dp, rp->styleIndex);
-
- if(style->platform != gxGlyphPlatform) {
-
- /* BUG ALERT!!!! We must put code in that handles the finding
- of separators nomatter what the text size. This code is wrong
- when two byte text data is being traversed */
-
- ptr = (char *) *rp->text + runOffset - 1;
-
- for(; runOffset > 0; runOffset--, ptr--, textToCheck--) {
-
- if(textToCheck <= 0)
- return(endOffset);
-
- if(*ptr == ' ')
- return(rp->paraOffset + runOffset);
-
- }
-
- } else {
-
- textToCheck -= runOffset;
-
- if(textToCheck <= 0)
- return(endOffset);
-
- }
-
- if(runIndex)
- runOffset = (rp-1)->numText;
-
- }
-
- return(endOffset);
-
- }
-
- static void CheckAttributes(DocPtr dp, NewRunPtr rp, AttrPtr ap)
- {
- gxFont * fp;
- short * sp;
- short i;
- gxFont runTextFont;
- short runTextSize;
-
- runTextFont = GetDocStyleTextFont(dp, rp->styleIndex);
- runTextSize = GetDocStyleTextSize(dp, rp->styleIndex);
-
- if(ap->start) {
-
- ap->fonts = (gxFont **) NewHandle(sizeof(gxFont));
- ap->numFonts = 1;
-
- (*ap->fonts)[0] = runTextFont;
-
- ap->styles = (short **) NewHandle(sizeof(short));
- ap->numStyles = 1;
-
- (*ap->styles)[0] = rp->styleIndex;
-
- if(rp->styleIndex < 0 || rp->styleIndex >= dp->numStyles)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- ap->size = runTextSize;
- ap->start = false;
-
- } else {
-
- /* add the gxFont */
-
- fp = *ap->fonts;
-
- for(i=0; i<ap->numFonts; i++, fp++)
- if(*fp == runTextFont)
- break;
-
- if(i == ap->numFonts) {
-
- ap->numFonts++;
- SetHandleSize((Handle) ap->fonts, ap->numFonts * sizeof(gxFont));
-
- (*ap->fonts)[ap->numFonts-1] = runTextFont;
-
- }
-
- /* add the style */
-
- sp = *ap->styles;
-
- for(i=0; i<ap->numStyles; i++, sp++)
- if(*sp == rp->styleIndex)
- break;
-
- if(i == ap->numStyles) {
-
- ap->numStyles++;
- SetHandleSize((Handle) ap->styles, ap->numStyles * sizeof(short));
-
- (*ap->styles)[ap->numStyles-1] = rp->styleIndex;
-
- if(rp->styleIndex < 0 || rp->styleIndex >= dp->numStyles)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- if(ap->size != runTextSize)
- ap->size = kUndefinedSize;
-
- }
-
- }
-
- static void CleanUpRuns(DocPtr dp, ParaPtr pp, short startRunIndex)
- {
- NewRunPtr rp;
- short runIndex;
-
- if(startRunIndex < 0 || startRunIndex >= pp->numRuns)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(pp->numRuns == 0)
- return;
-
- if(startRunIndex > 0)
- startRunIndex--;
-
- HLock((Handle) pp->runs);
-
- runIndex = startRunIndex;
- rp = *pp->runs + runIndex;
-
- while(runIndex < pp->numRuns) {
-
- if (rp->numText == 0) {
-
- /* remove empty runs */
-
- DisposeNewRun(dp, rp);
-
- BlockMove((Ptr) (rp+1), (Ptr) rp, (pp->numRuns - runIndex - 1) * sizeof(NewRunRec));
- pp->numRuns--;
-
- HUnlock((Handle) pp->runs);
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- } else {
- runIndex++;
- rp++;
- }
-
- }
-
- runIndex = startRunIndex;
- rp = *pp->runs + runIndex;
-
- while(runIndex < pp->numRuns) {
-
- if(runIndex < (pp->numRuns - 1) && (rp->styleIndex == (rp+1)->styleIndex)) {
-
- /* join like runs */
-
- JoinNewRuns(dp, rp, (rp + 1));
-
- pp->numRuns--;
-
- BlockMove((Ptr) (rp + 2), (Ptr) (rp+1), (pp->numRuns - runIndex - 1) * sizeof(NewRunRec));
-
- HUnlock((Handle) pp->runs);
-
- SetHandleSize((Handle) pp->runs, pp->numRuns * sizeof(NewRunRec));
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs + runIndex;
-
- } else {
- runIndex++;
- rp++;
- }
-
- }
-
- HUnlock((Handle) pp->runs);
-
- }
-